<?php
namespace app\client\wxpay;
include_once __DIR__ . '/wxpay/WxPay.Api.php';
/**
 * 统一下单对象
 * **/

class Mmpaymkttransfers {
    private $input = null;
    private $config = null;
    
    public function __construct($openId) {
        $this->input = new \MmpayMkttransfers();
        $this->input->SetOpenid($openId);
        
        $this->config = new \app\client\wxpay\Config();
        $this->config->setSignType('MD5');
    }
    
    public function setOrder($order) {
        $this->input->SetCheck_name(false);
        $this->input->SetDesc('提现到零钱');
        $this->input->SetPartner_trade_no($order['order_no']);
        $this->input->SetAmount($order['amount'] * 100);
    }
    
    public function transfer() {
        $order = \WxPayApi::mkttransfers($this->config, $this->input);
        $res = ['err' => 1, 'msg' => ''];
        if($order['return_code'] !== 'SUCCESS'){
            $res['msg'] = $order['return_msg'];
            return $res;
        }else{
            if($order['result_code'] !== 'SUCCESS'){
                $res['msg'] = $order['err_code_des'];
                return $res;
            }
        }
        $res['payment_time'] = $order['payment_time'];
        $res['payment_no'] = $order['payment_no'];
        $res['err'] = 0;
        
        return $res;
    }
}